import ioutilities.*;
import java.util.*;

public class ConsoleCalcUI extends UI {

	CalcInterface myCalc;
	IOUtilitiesInterface cio = new ConsoleIOUtilities();

	public ConsoleCalcUI(Model m) {

		myCalc = (CalcInterface)m;

	}

	public void start() {

	ArrayList<String> options = new ArrayList<String>();
	options.add("See the calc");
	options.add("Set X");
	options.add("Set Z");

	boolean done = false;

	while (!done) {
		int answer = cio.getMenuOption("What next? ", options);
		switch (answer) {
			case 0: doInspect(); break;
			case 1: doSetX();    break;
			case 2: doSetY();    break;
			case 3: doSetZ();    break;
			case 4: myCalc.clear();  break;
			case 5: done = true; break;
			default:  throw new RuntimeException("Blew through menu!");
		}
	}
}

	private void doInspect() {
		cio.println(myCalc.inspect());
	}

	private void doSetX() {
		myCalc.setX(cio.getDouble("New X Value: "));
	}

	private void doSetY() {
		try {
			myCalc.setY(cio.getDouble("New Y Value: "));
		} catch (IllegalArgumentException e) {
			cio.println("Zero values for Y not allowed");
		}
	}

	private void doSetZ() {
			myCalc.setZ(cio.getDouble("New Z Value: "));
	}

	/**************************/

	public void update(Observable who, Object what) {
		System.out.println("Updated with " + who + " and " + what);
	}
}
